﻿using System.Collections.Generic;
using System.Web.Mvc;
using Data;
using Models;
using System.Collections;

namespace Web.Controllers
{
    public class SearchController : BaseController
    {
        //
        // GET: /search/
        public SearchController()
        {
            var dbCategory = new CategoryData();
            ViewBag.NewsCategories = dbCategory.GetCategories();
            var dbTags = new TagsData();
            ViewBag.NewsTags = dbTags.GetTags();
        }

        public ActionResult Index()
        {
            return Redirect("/home");
        }

        [HttpPost]

        public ActionResult GetResult(string searchText, int? page)
        {
            var dbDiff = new DifferentData();
            var newsList = dbDiff.Search(searchText);

            if (newsList != null)
            {
                var pager = new Pager(newsList.Count, Request.Url.LocalPath,page);
                ViewBag.pager = pager;

                return View("Result",newsList);
            }

            return View("noResult");
        }

    }
}
